package com.film.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.film.service.UserService;
import com.film.service.impl.UserServiceImpl;
/**
 * 该控制类用来做登录
 * @author 2119196781
 *
 */
@WebServlet("/login.do")
public class LoginController extends HttpServlet{
	private UserService userService = new UserServiceImpl();
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String username = request.getParameter("username");
		String password = request.getParameter("password");

		
		Map<String,Object> loginMsg = userService.login(username, password);
		if(loginMsg.get("user")!=null) {
			request.getSession().setAttribute("userLogin",loginMsg.get("user"));
			response.sendRedirect("index");
		}else {
			request.setAttribute("msg", loginMsg.get("msg"));
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}
	}
}
